@import plugins.Context
@import org.silkframework.rule.execution.TransformReport
@import org.silkframework.rule.execution.TransformReport.RuleResult
@import org.silkframework.rule.execution.TransformReport.RuleError
@import org.silkframework.rule.TransformSpec
@import org.silkframework.config.Prefixes

@(statistics: TransformReport, prefixes: Prefixes)

@if(statistics.ruleResults.isEmpty) {
  <div>
    No validation issues
  </div>
} else {
  @issueTable
}

@issueTable = {
  <table class="mdl-data-table mdl-js-data-table">
    <thead>
      <tr>
        <th>Rule</th>
        <th>Entity</th>
        <th>Values</th>
        <th>Issue</th>
      </tr>
    </thead>
    <tbody>

    @for((ruleName, RuleResult(errorCount, sampleErrors)) <- statistics.ruleResults) {
      <tr class="mdl-color--blue-grey-100">
        <td><b>@ruleName</b></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>

      @if(sampleErrors.isEmpty) {
        <tr>
          <td></td>
          <td>
            No issues
          </td>
          <td></td>
          <td></td>
        </tr>
      } else {
        @for(RuleError(entity, values, exception) <- sampleErrors) {
          <tr>
            <td></td>
            <td>
              <a href="@entity" target="_blank" >@prefixes.shorten(entity)</a>
            </td>
            <td>@values.flatten.mkString(", ")</td>
            <td>@exception.getMessage</td>
          </tr>
        }
      }
    }

    </tbody>
  </table>
}